<?php

/**
 * This file is part of the Codizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Codizer Core Team <team@codizer.org>
 * @package     Codizer
 */

class f_mail_MailService extends f_mail_MailMessage
{
	private static $instance;
	
	/**
	 * @return f_mail_MailService
	 */
	private function __construct()
	{
		return $this;
	}
	
	/**
	 * Get singleton instance
	 *
	 * @return f_mail_MailService
	 */
	public static function getInstance()
	{
		if(self::$instance === null)
		{
			self::$instance = new self();
		}
		return self::$instance;
	}
	
	/**
	 * Send the mail and return true if ok or and PearError
	 *
	 * @param f_mail_MailMessage $mailMessage
	 * @return mixed boolean
	 */
	public function send()
	{
		$mailMime = f_mail_MailMime::getInstance($this);
		$receiver = ( $this->getReceiverName()!=null ? $this->getReceiverName()." <".$this->getReceiver().">" : $this->getReceiver() );
		return mail($receiver, $this->getSubject(), $mailMime->getHTML(), $mailMime->getHeaders());
	}	
}